<?php
namespace Home\Controller;
use Think\Controller;
class RecordController extends Controller {

	public function _initialize()
    {
        //未登录、登录超时、长时间未动
    	if (empty($_SESSION['uid']) || time() > $_SESSION['overtime'] || empty($_SESSION['overtime']) ) {

    		$this->redirect('Common/login');
    	}

        session('overtime',(time()+60*60*C('overtime')));

        
    }


    /**
     * [center 中心积分]
     * @return [type] [description]
     */
    public function center(){
    	$m_center = M('Center');
    	$uid = $_SESSION['uid'];

    	$where['user_id'] = $uid;

    	$count = $m_center->where($where)->count();
        $Page  = new \Think\Page($count,20);
        $show  = $Page->show();

        
        $centerList = $m_center->where($where)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

		$this->assign('page',$show);
        $this->assign('centerList',$centerList);
    	$this->display();
    }


    /**
     * [task 任务积分]
     * @return [type] [description]
     */
    public function task(){
    	$m_task = M('Task');
    	$uid = $_SESSION['uid'];

    	$where['user_id'] = $uid;

    	$count = $m_task->where($where)->count();
        $Page  = new \Think\Page($count,20);
        $show  = $Page->show();

        
        $taskList = $m_task->where($where)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

		$this->assign('page',$show);
        $this->assign('taskList',$taskList);
    	$this->display();
    }


    /**
     * [trading 交易积分]
     * @return [type] [description]
     */
    public function trading(){
        $m_trading = M('Trading');
        $uid = $_SESSION['uid'];

        $where['user_id'] = $uid;

        $count = $m_trading->where($where)->count();
        $Page  = new \Think\Page($count,20);
        $show  = $Page->show();

        
        $tradingList = $m_trading->where($where)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

        $this->assign('page',$show);
        $this->assign('tradingList',$tradingList);
        $this->display();
    }


    /**
     * [key_dynamic 动态秘钥]
     * @return [type] [description]
     */
    public function key_dynamic(){
        $m_keydynamic = M('Key_dynamic');
        $uid = $_SESSION['uid'];

        $where['user_id'] = $uid;
        $count = $m_keydynamic->where($where)->count();
        $Page  = new \Think\Page($count,20);
        $show  = $Page->show();

        
        $keydynamicList = $m_keydynamic->where($where)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

        $this->assign('page',$show);
        $this->assign('keydynamicList',$keydynamicList);
        $this->display();
    }


    /**
     * [key_task 任务秘钥]
     * @return [type] [description]
     */
    public function key_task(){
        $m_keytask = M('Key_task');
        $uid = $_SESSION['uid'];

        $where['user_id'] = $uid;
        $count = $m_keytask->where($where)->count();
        $Page  = new \Think\Page($count,20);
        $show  = $Page->show();

        
        $keytaskList = $m_keytask->where($where)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

        $this->assign('page',$show);
        $this->assign('keytaskList',$keytaskList);
        $this->display();
    }
}